define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'byd_user_ty/index' + location.search,
                    add_url: 'byd_user_ty/add',
                    edit_url: 'byd_user_ty/edit',
                    del_url: 'byd_user_ty/del',
                    multi_url: 'byd_user_ty/multi',
                    import_url: 'byd_user_ty/import',
                    table: 'byd_user_ty',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'bhid', title: __('身份编码'), operate: 'LIKE'},
                        {field: 'realname', title: __('真实姓名'), operate: 'LIKE'},
                        {field: 'username', title: __('昵称'), operate: 'LIKE'},
                        {field: 'orderid', title: __('订单号'), operate: 'LIKE'},
                        {field: 'idcard', title: __('身份证号'), operate: 'LIKE'},
                        {field: 'yhid', title: __('银行卡号'), operate: 'LIKE'},
                        {field: 'cjprice', title: __('成交金额'), operate: 'LIKE'},
                        {field: 'price', title: __('提现金额'), operate: 'LIKE'},
                        {field: 'level', title: __('提佣身份'), searchList: {"1":__('1级美居会员'),"2":__('2级美居会员'),"3":__('2级设计师会员'),"4":__('3级设计师会员'),"5":__('1级设计师会员')}, formatter: Table.api.formatter.normal},
                        {field: 'bl', title: __('提佣比例'), operate: 'LIKE'},
                        {field: 'type', title: __('提佣类型'), operate: 'LIKE'},
                        {field: 'addtime', title: __('下单时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('申请时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'auto', title: __('状态'), searchList: {"0":__('未打款'),"1":__('已打款')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    $(document).on("click", ".btn-export", function () {
        var table = $("#table");
// kT8McdtFrIL5UUSo4fjcHA==
        var ids = Table.api.selectedids(table);
        console.log(ids);
  var ids = ($.isArray(ids) ? ids.join(",") : ids);
  var options = {url: "byd_user_ty/export", data: {action: "POST", ids: ids}};
       Layer.confirm(
                    "确定打款吗",
                    {icon: 3, title: __('Warning'), shadeClose: true},
                    function (index) {
             Fast.api.ajax(options, function (data, ret) {
                Toastr.success(data.msg);
                table.bootstrapTable('refresh');
            }, function (data, ret) {

            });
                        Layer.close(index);
                    }
                );

});
    // $(document).on("click", ".btn-export", function () {
    //     var table = $("#table");
    //     var ids = Table.api.selectedids(table);
    //     var page = table.bootstrapTable('getData');
    //     var all = table.bootstrapTable('getOptions').totalRows;
    //     console.log(ids);
    //
    //     Layer.confirm("请选择打款的选项<form action='" + Fast.api.fixurl("byd_user_ty/export") + "' method='post' target='_blank'><input type='hidden' name='ids' value='' /><input type='hidden' name='filter' ><input type='hidden' name='op'><input type='hidden' name='search'><input type='hidden' name='columns'></form>", {
    //         title: '打款',
    //         btn: ["选中项(" + ids.length + "条)", "本页(" + page.length + "条)"],
    //         success: function (layero, index) {
    //
    //             $(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
    //
    //         }
    //         , yes: function (index, layero) {
    //             submitForm(ids.join(","), layero);
    //             return false;
    //         }
    //         ,
    //         btn2: function (index, layero) {
    //             var ids = [];
    //             $.each(page, function (i, j) {
    //                 ids.push(j.id);
    //             });
    //             submitForm(ids.join(","), layero);
    //             return false;
    //         }
    //         ,
    //         btn3: function (index, layero) {
    //             submitForm("all", layero);
    //             return false;
    //         }
    //     })
    // });
    // var submitForm = function (ids, layero) {
    //     var table = $("#table");
    //     var options = table.bootstrapTable('getOptions');
    //     console.log(options);
    //     var columns = [];
    //     $.each(options.columns[0], function (i, j) {
    //         if (j.field && !j.checkbox && j.visible && j.field != 'operate') {
    //             columns.push(j.field);
    //         }
    //     });
    //     var search = options.queryParams({});
    //     $("input[name=search]", layero).val(options.searchText);
    //     $("input[name=ids]", layero).val(ids);
    //     $("input[name=filter]", layero).val(search.filter);
    //     $("input[name=op]", layero).val(search.op);
    //     $("input[name=columns]", layero).val(columns.join(','));
    //     $("form", layero).submit();
    // };
    return Controller;
    // return Controller;
});